<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue中JS动画与velocity.js</title>  
    <script src="./vue.js"></script>
    <script src="./velocity.min.js"></script>
</head>
<body>
    <div id="root">
        <transition 
            name='fade'
            @before-enter='handleBeforeEnter'
            @enter='handleEnter'
            @after-enter='handleAfterEnter'

            @before-leave='handleBeforeleave'
            @leave='handleleave'
            @after-leave='handleAfterleave'
        >
            <div v-if='show'>Hello World!</div>
        </transition>
        <button @click=handleBtnClick>切换</button>
    </div>
    <script>

        var vm = new Vue({
            el:'#root',
            data:{
                show:true
            },
            methods:{
                handleBtnClick:function(){
                    this.show = !this.show
                },
                handleBeforeEnter:function(el){
                    el.style.opacity = 0
                },
                handleEnter:function(el,done){
                    Velocity(el,{
                        opacity:1
                    },{
                        duration:5000,
                        complete:done
                    })
                },
                handleAfterEnter:function(el){
                    alert('动画完成')
                },
                handleBeforeleave:function(el){
                    el.style.color = 'orange'
                },
                handleleave:function(el,done){
                    setTimeout(() => {
                        el.style.color = 'pink'
                    },2000)
                    setTimeout(() => {
                        done()
                    },4000)
                },
                handleAfterleave:function(el){
                    el.style.color = 'blue'
                }
                }
        })
    </script>
</body>
</html>